package com.angenela.lmz.controller;

import com.angenela.lmz.constant.Constant;
import com.angenela.lmz.dto.ObjectDTO;
import com.angenela.lmz.mapper.TagMapper;
import com.angenela.lmz.pojo.Tag;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "标签相关接口")
@RestController
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagMapper tagMapper;
    @Autowired
    private ObjectMapper objectMapper;

    @GetMapping("/")
    @ApiOperation("获取所有标签的名称和id")
    public String getAllTags() throws JsonProcessingException {
        ObjectDTO dto = new ObjectDTO();

        List<Tag> tags = tagMapper.getAllTags();
        dto.setData(tags);
        dto.setCode(Constant.SUCCESS_CODE);

        return objectMapper.writeValueAsString(dto);
    }
}
